//1、下载
//2、引入
import VueRouter from "vue-router";
import Vue from "vue";
//3、注册
Vue.use(VueRouter)
//4、路由规则
let routes = [
    {
        path: "/",
        redirect: "/login"
    },
    {
        path: "/login",
        component: () => import("../views/login.vue")
    },
    {
        path: "/register",
        component: () => import("../views/register.vue")
    }, {
        path: "/personal",
        component: () => import("../views/personal.vue")
    }, {
        path: "/edit_profile",
        component: () => import("../views/edit_profile.vue")
    }
    , {
        path: "/index",
        component: () => import("../views/index.vue")
    }
    , {
        path: "/articleDetail",
        component: () => import("../views/articleDetail.vue")
    }
    , {
        path: "/commentList",
        component: () => import("../views/commentList.vue")
    }
    , {
        path: "/myFollow",
        component: () => import("../views/myFollow.vue")
    }
]


//5、生成路由对象
let router = new VueRouter({
    routes
})

router.beforeEach((to, from, next) => {
    let token = localStorage.getItem("ly-14-token")
    if (to.path === "/personal" && !token) {
        next("/login")
    } else {
        next()
    }
})
//6、导出路由对象
export default router